-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support F_GETFL and F_SETFL for fcntl #4212
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rustbot ready
let [flag] = check_min_vararg_count(cmd_name, varargs)?; | ||
let flag = this.read_scalar(flag)?.to_i32()?; | ||
|
||
// FIXME: File access mode and file creation flags should be ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the man page:
F_SETFL (int)
Set the file status flags to the value specified by arg.
File access mode (O_RDONLY, O_WRONLY, O_RDWR) and file
creation flags (i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC)
in arg are ignored.
There are quite a few file access mode and file creation flags, would prefer to open an issue for this and do it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the first round of comments. Sorry for the long wait!
@rustbot author
|
||
// We only support F_GETFL for socketpair and pipe. | ||
let anonsocket_fd = fd.downcast::<AnonSocket>().ok_or_else(|| { | ||
err_unsup_format!("fcntl: only socketpair / pipe are supported for F_SETFL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err_unsup_format!("fcntl: only socketpair / pipe are supported for F_SETFL") | |
err_unsup_format!("fcntl: only socketpair / pipe are supported for F_GETFL") |
})?; | ||
|
||
if anonsocket_fd.is_nonblock() { | ||
// socketpair's SOCK_NONBLOCK and pipe's O_NONBLOCK have the same value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fcntl docs seem to anyway indicate that we always return the O_*
flags here. So this fact should not matter.
If it actually did matter, we should have an assert_eq!
here.
err_unsup_format!("fcntl: only socketpair / pipe are supported for F_GETFL") | ||
})?; | ||
|
||
let cmd_name = "fcntl(fd, F_SETFL, ...)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please inline this let
.
if flag == this.eval_libc_i32("O_NONBLOCK") { | ||
anonsocket_fd.set_nonblock(); | ||
} else { | ||
throw_unsup_format!("fcntl: only O_NONBLOCK are supported for F_GETFL") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also support un-setting the O_NONBLOCK
flag, right? I assume that's what happens on flag == 0
.
@@ -40,7 +40,7 @@ struct AnonSocket { | |||
/// A list of thread ids blocked because the buffer was full. | |||
/// Once another thread reads some bytes, these threads will be unblocked. | |||
blocked_write_tid: RefCell<Vec<ThreadId>>, | |||
is_nonblock: bool, | |||
is_nonblock: Cell<bool>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_nonblock: Cell<bool>, | |
/// Whether this is a non-blocking socket or not. | |
is_nonblock: Cell<bool>, |
// 2. Thread 1 set O_NONBLOCK flag on fds[0], then check the value of F_GETFL. | ||
// 3. Thread 2 writes to fds[1] to unblock the `read` in main thread. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this done by 2 different threads?
Reminder, once the PR becomes ready for a review, use |
This PR supports
F_SETFL
andF_GETFL
flags forfcntl
. In this implementation,F_SETFL
can only setO_NONBLOCK
flag.The interaction between these
fcntl
operations and blocking fd is summarised here.Fixes #4119